package org.hong.monkey.scheduler

import org.hong.monkey.util.ListenerBus

private[monkey] trait MonkeyListenerBus extends ListenerBus[MonkeyListener, MonkeyListenerEvent] {

  override def onPostEvent(listener: MonkeyListener, event: MonkeyListenerEvent): Unit = {
    event match {
      case stageSubmitted: MonkeyListenerStageSubmitted =>
        listener.onStageSubmitted(stageSubmitted)
      case stageCompleted: MonkeyListenerStageCompleted =>
        listener.onStageCompleted(stageCompleted)
      case jobStart: MonkeyListenerJobStart =>
        listener.onJobStart(jobStart)
      case jobEnd: MonkeyListenerJobEnd =>
        listener.onJobEnd(jobEnd)
      case taskStart: MonkeyListenerTaskStart =>
        listener.onTaskStart(taskStart)
      case taskGettingResult: MonkeyListenerTaskGettingResult =>
        listener.onTaskGettingResult(taskGettingResult)
      case taskEnd: MonkeyListenerTaskEnd =>
        listener.onTaskEnd(taskEnd)
      case environmentUpdate: MonkeyListenerEnvironmentUpdate =>
        listener.onEnvironmentUpdate(environmentUpdate)
      case blockManagerAdded: MonkeyListenerBlockManagerAdded =>
        listener.onBlockManagerAdded(blockManagerAdded)
      case blockManagerRemoved: MonkeyListenerBlockManagerRemoved =>
        listener.onBlockManagerRemoved(blockManagerRemoved)
      case unpersistRDD: MonkeyListenerUnpersistRDD =>
        listener.onUnpersistRDD(unpersistRDD)
      case applicationStart: MonkeyListenerApplicationStart =>
        listener.onApplicationStart(applicationStart)
      case applicationEnd: MonkeyListenerApplicationEnd =>
        listener.onApplicationEnd(applicationEnd)
      case metricsUpdate: MonkeyListenerExecutorMetricsUpdate =>
        listener.onExecutorMetricsUpdate(metricsUpdate)
      case executorAdded: MonkeyListenerExecutorAdded =>
        listener.onExecutorAdded(executorAdded)
      case executorRemoved: MonkeyListenerExecutorRemoved =>
        listener.onExecutorRemoved(executorRemoved)
      case blockUpdated: MonkeyListenerBlockUpdated =>
        listener.onBlockUpdated(blockUpdated)
      case logStart: MonkeyListenerLogStart => // ignore event log metadata
    }
  }

}
